package com.uidp.search;

import static com.uidp.hibernatelayer.AttributesDAO.MODULELEMENTS;
import static org.hibernate.criterion.Restrictions.idEq;

import com.acsior.sbc.exception.BusinessException;
import com.acsior.sbc.exception.SearchException;
import com.acsior.sbc.impl.hibernate.SearchHibernateBusinessObject;
import com.uidp.domain.Attributes;
import com.uidp.domain.ModulElements;
import com.uidp.hibernatelayer.AttributesDAO;
import com.uidp.hibernatelayer.AttributesVO;

public class AttributeSearch extends
		SearchHibernateBusinessObject<AttributesVO, AttributesDAO, Attributes> {

	private Attributes criteriaAttribue;

	public AttributeSearch() throws BusinessException {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	protected Attributes createResultObject(AttributesVO d)
			throws BusinessException {
		return new Attributes(d);
	}

	/** @see SearchHibernateBusinessObject#buildCriteria() */
	@Override
	protected void buildCriteria() throws SearchException {
		super.buildCriteria();
		if (getModulEl() != null && getModulEl().isEditMode()) {
			getCriteria().createCriteria(MODULELEMENTS).add(
					idEq(getModulEl().getId()));
		}
	}

	/** @see SearchObject#initialize() */
	@Override
	protected final void initialize() throws BusinessException {
		super.initialize();

		this.criteriaAttribue = new Attributes();
	}

	@Override
	protected Class<AttributesDAO> getDAOClass() {
		return AttributesDAO.class;
	}

	public Attributes getCriteriaAttribue() {
		return criteriaAttribue;
	}

	public void setCriteriaAttribue(Attributes criteriaAttribue) {
		this.criteriaAttribue = criteriaAttribue;
	}

	public ModulElements getModulEl() {
		return getCriteriaAttribue().getModulElements();
	}

	public void setModulEl(ModulElements modulEl) {
		getCriteriaAttribue().setModulElements(modulEl);
	}

}
